# 用面向对象读取csv文件，进行接口测试
import csv

import requests


class check_test():
    def __init__(self):
        self.url = 'http://10.211.55.5:8080/jwshoplogin/user/check_vaild.do'

    def checktest(self):
        # 从csv文件读取用例
        checkinfo = {}
        file1 = open('../../test_data/independence_interface_data/check_username_email.csv', 'r')
        file2 = open('../../../interface_test/test_result/check_test_results.csv', 'w')

        table = csv.reader(file1)
        for row in table:
            checkinfo['str'] = row[0]
            checkinfo['type'] = row[1]
            s = requests.session()
            responce = s.post(self.url, data=checkinfo).text
            r = responce.find(row[2])
            if r>0:
                file2.write(row[0] + ',' + row[1] + ',' + row[2] + ',' + '测试通过' + '\n')
            else:
                file2.write(row[0] + ',' + row[1] + ',' + row[2] + ',' + '测试失败' + '\n')
        file2.close()


if __name__ == '__main__':
    checkobj = check_test()
    checkobj.checktest()
